package com.wb.mas.ui.order;


import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.wb.mas.R;
import com.wb.mas.app.AppViewModelFactory;
import com.wb.mas.databinding.ActOrderBinding;

import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.BaseActivity;
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter;

/**
 * Copyright (C) 2018,
 * OrderActivity
 * <p>
 * Description
 * 订单
 *
 * @author yue
 * @version 1.0
 * <p>
 * Ver 1.0, 2019-04-30, yue, Create file
 */
public class OrderActivity extends BaseActivity<ActOrderBinding, OrderViewModel> {

    public static final int ORDER_BORROW = 0;
    public static final int ORDER_COMPLETE = 1;
    /**
     *
     */
    private int type;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.act_order;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initParam() {
        type = getIntent().getIntExtra("type", ORDER_BORROW);
    }

    @Override
    public void initData() {
        binding.setAdapter(new BindingRecyclerViewAdapter());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public OrderViewModel initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        OrderViewModel orderViewModel = ViewModelProviders.of(this, factory).get(OrderViewModel.class);
        orderViewModel.type = type;
        return orderViewModel;
    }

    @Override
    public void initViewObservable() {
        //监听下拉刷新完成
        viewModel.uc.finishRefreshing.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                //结束刷新
                binding.twinklingRefreshLayout.finishRefreshing();
            }
        });
        //监听上拉加载完成
        viewModel.uc.finishLoadmore.observe(this, new Observer() {
            @Override
            public void onChanged(@Nullable Object o) {
                //结束刷新
                binding.twinklingRefreshLayout.finishLoadmore();
            }
        });
    }


}
